<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>添加公司
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form action="/admin_company/add" method="post" enctype="multipart/form-data">
                        <div class="form-group ">
                            <label for="companyname">公司名称</label>
                            <input type="text" placeholder="输入公司名称" id="companyname" class="form-control" name="companyname">
                        </div>
                        <div class="form-group ">
                            <label for="companyname">公司类型</label>
                            <input type="text" placeholder="输入公司类型" id="type" class="form-control" name="type">
                        </div>
                        <div class="form-group ">
                            <label for="companyname">公司等级</label>
                            <input type="text" placeholder="输入公司等级" id="grades" class="form-control" name="grades">
                        </div>
                        <div class="form-group ">
                            <label for="introduce">公司简介</label>
                            <textarea id="introduce" style="height:100px" placeholder="输入公司简介" class="form-control" name="introduce"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="pic">公司logo</label>
                            <input type="file" id="file_input" name="pic">
                        </div>
                        <div class="form-group">
                            <label for="url">联系地址</label>
                            <input type="text" placeholder="输入联系地址" id="address" class="form-control" name="address">
                        </div>
                        <button class="btn btn-primary demo_2" type="button" id="submit">添加</button>
                    </form>
                </div>
                <div class="container-fluid col-md-5">
                    <div class="images text-center" id="img_view">
                    </div>
                </div>
            </div>
        </div>
        <div class="subviews">
            <div class="subviews-container"></div>
        </div>
    </div>
    <!-- end: PAGE -->
</div>

<script>
$(function(){
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_add(responseText,'/admin_company','/admin_company/add');
    }
    $('#submit').click(function() {
        $('form').ajaxSubmit(options);
        return false;

    });
});
var result = document.getElementById("img_view");
var input = document.getElementById("file_input");

if(typeof FileReader==='undefined'){
   result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
   input.setAttribute('disabled','disabled');
}else{
   input.addEventListener('change',readFile,false);
}
function readFile(){
   var file = this.files[0];
   if(!/image\/\w+/.test(file.type)){
       alert("文件必须为图片！");
       return false;
   }
   var reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function(e){
       result.innerHTML = '<img src="'+this.result+'" alt="" width="400px"/>'
   }
}
</script>
<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
